using System;
using System.Collections.Generic;
using ScrumManagementTool.db.interfaces;
using ScrumManagementTool.domain.interfaces;

namespace ScrumManagementTool.db
{
    public class DbProject : IDbProject
    {
        private IDbGateway dbGateway;

        public DbProject():this(new DbGateway())
        {
            
        }

        public DbProject(IDbGateway dbGateway)
        {
            this.dbGateway = dbGateway;
        }

        public void AddNewProject(string name)
        {
            string stmt = "INSERT INTO project (name) " +
                          "VALUES (:name)";

            IDictionary<string, string> values = new Dictionary<string, string>();
            values.Add(new KeyValuePair<string, string>(":name", name));

            dbGateway.ExecuteInsertStatement(stmt, values);
        }

        public IList<string> GetAllProjectNames()
        {
            string stmt = "SELECT name FROM project";
            var data = dbGateway.ExecuteSelectStatement(stmt, new Dictionary<string, string>());
            IList<string> projectNames = new List<string>();
            foreach (var row in data)
            {
                projectNames.Add(row["name"].ToString());
            }
            return projectNames;
        }
    }
}